<?php
	
	namespace Aspic\Image;
	use Aspic as A;

	class JPEG extends AbstractImage  {
		
		public function __construct($path = null, $width = 1, $height = 1) {
			parent::__construct($path);
			
			if($path) {
				$this->_img = imagecreatefromjpeg($path);
				
				if(!is_resource($this->_img)) {
					static::throwImageCreationError();
				}
			}
			else {
				$this->_img = imagecreate($width, $height);
			}
		}
		
		public function save($path = null, $quality = 75) {
			$path = A\Util::ifSet($path, $this->_path);
			
			$res = imagejpeg($this->_img, $path, $quality);
			
			if(!$res) {
				throw new A\Exception('Problem while saving image file: "'.$path.'"');
			}
		}
		
		public function percentQuality($pc) {
			$quality = 100 * $pc;
			
			return $quality;
		}
	}
	
?>